package com.operation.net.controller;


import com.operation.net.common.ApiRestResponse;
import com.operation.net.model.InterFlow;
import com.operation.net.model.Interface;
import com.operation.net.model.SystemInfo;
import com.operation.net.service.impl.DeviceViewServiceImpl;
import com.operation.net.service.impl.InterFlowService;
import com.operation.net.service.impl.InterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/device")
public class DeviceViewController {

    @Autowired
    private DeviceViewServiceImpl deviceViewService;

    @Autowired
    private InterfaceService interfaceService;

    @Autowired
    private InterFlowService interFlowService;



    @GetMapping("/select")
    public List<SystemInfo> getDevices(){
        return deviceViewService.getDevices();
    }

    //返回服务器接口信息
    @RequestMapping("/getinterface")
    public List<Interface> showInterfaceName(@RequestParam String ip){
        return deviceViewService.getInfaceInfo(ip);
    }


    //接口流量信息
    @RequestMapping("/getinterflow")
    public List<InterFlow> showInterflow(@RequestParam String ip, @RequestParam String interName) {
        return deviceViewService.getInfaceflow(ip, interName);
    }

    //收集接口流量信息
    @RequestMapping("/insert")
    public ApiRestResponse showInter() {

        try {
            interFlowService.getFlow();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ApiRestResponse.success();
    }

//    //插入接口信息
//    @RequestMapping("/insertInfo")
//    public void insertInfo() {
//
//        try {
//            interfaceService.GetInterInfo("192.168.237.19");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }

    //过滤空数据
    @RequestMapping("/filteremptydata")
    public List<Interface> filteremptydata(@RequestParam String ip){
        return deviceViewService.getInfaceInfoFilterEmptydata(ip);
    }

    //接口总流量
    @RequestMapping("/getAllInterflow")
    public List<InterFlow> getAllInterflow(@RequestParam String ip){
        return deviceViewService.getAllInfaceflow(ip);
    }


}
